package com.yunhe.sms.service.activite.impl;

import com.yunhe.commens.dto.Pagedao;
import com.yunhe.commens.util.DaoFactory;
import com.yunhe.sms.dao.activite.VoteItemDao;
import com.yunhe.sms.entity.activity.Voteitem;
import com.yunhe.sms.service.activite.VoteItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LeiPeifeng
 * @version V1.0
 * @date 2017/10/31 0031 14:58
 * @Description: 投票项
 */
@Service
public class VoteItemServiceImpl implements VoteItemService {
    @Autowired
    private VoteItemDao voteItemDao;
    @Override
    public void add(Voteitem voteItem) {
        voteItemDao.add ( voteItem );
    }

    @Override
    public void deleted(String ids) {
        if (null != ids && !ids.isEmpty ()){
            String[] split = ids.split ( "," );
            for (String id:split) {
                voteItemDao.deleted ( Long.valueOf ( id ) );
            }
        }
    }

    @Override
    public void update(Voteitem voteItem) {
        voteItemDao.update ( voteItem );
    }

    @Override
    public void count(Long id) {
        voteItemDao.count ( id);
    }

    @Override
    public Voteitem findId(Long id) {
        return voteItemDao.findId ( id );
    }

    @Override
    public List<Voteitem> find(Long voteId) {
        return voteItemDao.find ( voteId);
    }

    @Override
    public Pagedao<Voteitem> page(int offset, int limit,Long voteId) {
        Pagedao<Voteitem> pagedao =new Pagedao<> ();
        List<Voteitem> findpage=null;
        int count = voteItemDao.findcount ( voteId );//总数
        if (count>0){
            findpage = voteItemDao.findpage ( voteId,offset, limit );//本业数据
            pagedao.setPage ( offset/limit+1 );
            pagedao.setSize ( limit );
        }
        pagedao.setTotal ( count);
        pagedao.setRows ( findpage );
        return pagedao;
    }
}
